<?php

use Biz\module\Packages\Pay\PayAbstruct;
use Biz\service\package\PackageOrder;
use Biz\service\trade\Pay;
use Doraemon\model\Member;
use Doraemon\service\User;
class ConfirmOrderAction extends ActionPlugin
{
    const USER_LEVEL = self::LEVEL_REGISTER;
    const PAY_TIPS = "";
    public function main()
    {
        $packageId = $this->getRequest()->getPost('package_id', 0);
        $uid = $this->uid;
        if (!$packageId) {
            throw  new \Exception('参数错误');
        }
        // 查询当前用户
        $userInfo = User::getUserBaseInfo($uid);
        if (($userInfo['type'] == Member::USER_COMMON || $userInfo['type'] == Member::AUTH_USER_V)) {
            $packageInfo = PackageOrder::getPackage($packageId);
            $orderNo = PackageOrder::createOrderNo($packageId, $this->uid);
            if (empty($orderNo)) {
                throw new \Exception('当前课程无法购买');
            }
        } else {
            throw  new \Exception('用户不可购买');
        }
        // 用付费课的支付方式
        $payWays = Pay::getPayWays(PayAbstruct::_ANDROID_COURSE_PAY_WAYS_LIST);
        $payTips = self::PAY_TIPS;

        $data = [
            'order_no' => $orderNo,
            'summary' => [
                'total_amount' => $packageInfo['price'],
                'total_buynum' => 1
            ],

            'package_list' => [
                PackageOrder::PACKAGES[$packageId]
            ],
            'pay_ways' => $payWays,
            'pay_tips' => $payTips
        ];
        $this->setSuccess($data);
    }
}